package com.wimcorp.magic.abilities;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;

import com.wimcorp.magic.abilities.trigger.AbilityTrigger;
import com.wimcorp.magic.cards.PlayingCard;
import com.wimcorp.magic.exception.CastException;
import com.wimcorp.magic.input.Condition;
import com.wimcorp.magic.input.Location;
import com.wimcorp.magic.stack.Stack;

/**
 * example
 * {target:'OPPONENT',locations:['BATTLEFIELD'],behaviors:['DEATH_TOUCH']}
 * 
 * target options : OPPONENT
 * 
 * types options : 'CREATURE'
 * 
 * location options : STACK
 * 
 * destination : HAND,GRAVEYARD,EXILE,TOP_DECK,BOTTOM_DECK
 */
@Entity
@Table(name = "counterspell", schema = "abilities")
public class CounterSpell extends Ability {

	protected CounterSpell(){}
	
	public CounterSpell(AbilityTrigger trigger) {
		super(trigger);
	}
	
	public CounterSpell(CounterSpell ability){
		super(ability);
	}
	
	@Enumerated(EnumType.STRING)
	private Location destination;

	@Override
	protected void executeAbility() throws CastException {
		Stack stack = getPlayer().getOpponent().getStack();
		PlayingCard card = stack.getCard(getInput());
		stack.remove(card);
		switch (destination) {
		case BOTTOM_DECK:
			getPlayer().getOpponent().getDeck().addOnBottom(card);
			break;
		case EXILE:
			getPlayer().getOpponent().getSummoningPlaines().getExile().add(card);
			break;
		case GRAVEYARD:
			getPlayer().getOpponent().getSummoningPlaines().getGraveyard().add(card);
			break;
		case HAND:
			getPlayer().getOpponent().getHand().add(card);
			break;
		case TOP_DECK:
			getPlayer().getOpponent().getDeck().addOnTop(card);
			break;
		}

	}

	@Override
	public Ability clone() {
		return new CounterSpell(this);
	}

	public Location getDestination() {
		return destination;
	}

	public void setDestination(Location destination) {
		this.destination = destination;
	}

	
}
